import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { DeleteResult, Repository, UpdateResult } from 'typeorm';
import { VideoTag } from './videoTag.entity';

@Injectable()
export class VideoTagService {
  constructor(
    @InjectRepository(VideoTag)
    private repository: Repository<VideoTag>,
  ) {}

  findAll(): Promise<VideoTag[]> {
    return this.repository.find();
  }

  findOne(id: any): Promise<VideoTag> {
    return this.repository.findOne(id);
  }

  findAll_By_Video_Id(video_id: number): Promise<VideoTag[]> {
    return this.repository.find({where:{video_id:video_id}});
  }

  remove(id: number): Promise<DeleteResult> {
    return this.repository.delete({id});
  }

  update(id: number, tag_id: number): Promise<UpdateResult> {
    return this.repository.update({id},{tag_id});
  }

  create(cats: VideoTag): Promise<VideoTag> {
    return this.repository.save(cats);
  }
}
